package com.itheima.spring.bestpractive.utils;

import com.itheima.spring.bestpractive.mapping.AssessmentMapping;
import com.itheima.spring.bestpractive.pojo.AssessmentPlan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

/**
 * @version 1.0
 * @author: HZY
 * @date: 2025/7/10 10:03
 * @Content:
 */
@Component
public class MybatisTimeChange {
    @Autowired
    private AssessmentMapping assessmentMapping;

    @Scheduled(fixedDelay = 60*60*1000)
    public void changeTime() {
        Date now = new Date();
        List<AssessmentPlan> plans = assessmentMapping.selectAllPlan();
        for (AssessmentPlan plan : plans) {
            if (now.after(plan.getStartDate()) && now.before(plan.getEndDate())){
                assessmentMapping.updatePlanStatus(plan.getPlanId());
            }else if (now.after(plan.getEndDate())){
                assessmentMapping.updatePlanStatus2(plan.getPlanId());
            }
        }
    }
}
